package cn.itcast.activiti.servlet.user;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.TaskService;
import org.activiti.engine.task.Task;
import org.activiti.engine.task.TaskQuery;

import cn.itcast.activiti.common.ProcessEngineUtils;
/**
 * 查询用户任务
 * @author Administrator
 *
 */

@WebServlet("/queryUserTask.action")
public class QueryUserTaskServlet extends HttpServlet{
	private static final long serialVersionUID = 3118959238772590964L;
	
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		System.out.println("queryUserTask");
		//获取流程引擎
		ProcessEngine pe=ProcessEngineUtils.getProcessEngine();
		//获取任务服务
		TaskService taskService=pe.getTaskService();
		//创建任务查询对象
		TaskQuery taskQuery=taskService.createTaskQuery();
		
		//取出任务处理人
				String userId=(String) request.getSession().getAttribute("username");
		 /** 调用TaskQuery中方法完成查询 (添加任务处理人作为查询条件)*/
			List<Task> taskLists=taskQuery.taskAssignee(userId).list();
			
			request.setAttribute("taskLists", taskLists);
			request.getRequestDispatcher("/userTask.jsp").forward(request,response);
		
		
		
		
		
		
	}
	
	

}
